package com.mrguo.controller.basedata.goods;

import com.mrguo.common.entity.PageParams;
import com.mrguo.common.entity.Result;
import com.mrguo.vo.goods.GoodAndDetailsTempVo;
import com.mrguo.entity.bsd.GoodsTemp;
import com.mrguo.interfaces.ApiPermission;
import com.mrguo.service.impl.basedata.goods.GoodsTempServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName: GoodTempContrller
 * @Description:
 * @Author: 郭成兴（wx:512830037）
 * @Date 2020/11/5 8:33 上午
 * @Copyright 南通市韶光科技有限公司
 **/
@Api(tags = "商品模板")
@RestController
@RequestMapping("/goodTemp")
public class GoodTempContrller {

    @Autowired
    private GoodsTempServiceImpl goodsTempService;

    @ApiOperation(value = "新增或编辑模板")
    @ApiPermission(value = "goodtemp:adedit", pname = "新增编辑")
    @PostMapping("/saveData")
    public Result saveData(@RequestBody GoodAndDetailsTempVo goodAndDetailsTempVo) throws Exception {
        return Result.ok(goodsTempService.saveOrUpdateData(goodAndDetailsTempVo));
    }

    @ApiOperation(value = "删除模板")
    @ApiPermission(value = "goodtemp:del", pname = "删除")
    @PostMapping("/delData")
    public Result delData(@RequestBody Long id) throws Exception {
        return goodsTempService.delData(id);
    }

    @ApiOperation(value = "分页查询模板")
    @ApiPermission(value = "goodtemp:list", pname = "查询")
    @PostMapping("/listPage")
    public Result listData(@RequestBody PageParams<GoodsTemp> pageParams) throws Exception {
        return goodsTempService.listPage(pageParams);
    }

    @ApiOperation(value = "查询模板详情 by id")
    @ApiPermission(value = "goodtemp:list", pname = "查询")
    @PostMapping("/getData/{id}")
    public Result getDataById(@PathVariable Long id) throws Exception {
        return Result.ok(goodsTempService.getDataById(id));
    }
}
